
package threads;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import componentes.Configuracao;
import excessoes.LloginNuloException;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import principal.Main;

/**
 *
 * @author Wagner Tavares
 */
public abstract class Consulta implements Runnable{
    protected Configuracao config;
    protected String query;
    
    public Consulta(Configuracao config)  throws LloginNuloException{ 
        if(config.getLlogin() != null){    
            this.config=config;
        } else
            throw new LloginNuloException();
    }
    public abstract void run();
    protected ResultSet consultaBanco(String query){
        Connection con ;
        Statement st ;
        ResultSet result =null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://ads.fortalnet.com.br/cadastroparceiro?user=root&password=qwe!@#$");
            st = (Statement) con.createStatement();
            
            result = st.executeQuery(query);
            
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "Erro ao se conectar ao banco de dados", ex);
            return null;
        } catch (ClassNotFoundException e) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, " Não foi possível achar o driver jdbc", e);
            return null;
        }
        return result;
    }
    public void setQuery(String query){
        this.query = query;
    }
    public String getQuery(){
        return query;
    }
}
